<?php
/**
 * 材料报价管理
 * 
 * @author  Lee<a605333742@gmail.com>
 * @time    2016-07-31
 */
namespace Admin\Controller;

class PriceController extends CommonController{
    /*
     *构造函数
     * @return #
     */
    public function _initialize() {
        parent::_initialize();
        $this->db   =new \Model\PriceModel();
    }
    
    /*
     * 报价列表
     * 
     * @return #
     */
    public function index(){
        $map    =$this->_search("Price");
        if(session('type')<2){
            $map['publisherId'] =session("authId");
        }
        $map['state']   =2;
        $sortBy         ='top';
        $sort           =desc;
        $priceList      =$this->_list($this->db,$map,$sortBy,$sort);
        $this->assign("priceList",$priceList);
        $this->assign("act",1);
        show_bug($priceList);exit;
        $this->display();
    }
    
    /*
     * 待审核报价表
     * 
     * @return #
     */
    public function auditPrice(){
        $map    =$this->_search("Price");
        if(session('type')<2){
            $map['publisherId'] =session("authId");
        }
        $map['state']   =1;
        $sortBy         ="top";
        $sort           =desc;
        $priceList      =$this->_list($this->db,$map,$sortBy,$sort);
        $this->assign("priceList",$priceList);
        $this->assign("act",2);
        show_bug($priceList);exit;
        $this->display('index');
    }
    
    /*
     * 显示编辑信息
     * 
     * @return #
     */
    public function show(){
        $material   =D("Material")->select();        
        $region     =D("Region")->select();
        $this->assign("region",$region);
        $this->assign("material",$material);
        if(I("request.id")){
            $price  =$this->db->find(I("request.id","","int"));
            $this->assign("price",$price);
        }
        $this->display();
    }
    
    /*
     * 编辑报价信息
     * 
     * @return #
     */
    public function edit(){
        if(I("request.id")){
            $map['id']      =I("request.id",'','int');
        }
        if(I("request.level")){
            $map['level']   =I("request.level");
        }
        if(I("request.regionId")){
            $map['regionId']=I("request.regionId",'',"int");
        }
        if(I("request.offerPrice")){
            $map['offerPrice']  =I("request.offerPrice",'','trim');
        }
        if(I("request.offerPrice")){
            $map['top_sign']    =1;
        }
        $map['regionId']        =I("request.regionId",'','int');
        $map['materialId']      =I("request.materialId",'','int');
        $map['offerCompanyId']  =session("authId");
        
        if($this->db->edit($map)){
            $this->success("材料价钱编辑成功");
        }else{
            $this->error("材料价钱编辑失败");
        }
    }
    
    /*
     * 审核、批量审核报价信息
     * 
     * @return bool
     */
    public function alledit(){
        $map['id']      =I("request.id");
        $map['state']   =2;
        if($this->db->edits($map)){            
            $this->success("审核成功",U("index"));
        }else{
            $this->error("审核失败",U("index"));
        }
    }
    
    /*
     * 待审核，批量待审核
     * 
     * @return #
     */
    public function audit(){
        $map['id']      =I("request.id");
        $map['state']   =1;
        if($this->db->edits($map)){            
            $this->success("待审核成功",U("index"));
        }else{
            $this->error("待审核失败",U("index"));
        }
    }
    
    /*
     * 删除，批量删除求购信息
     * 
     * @return #
     */
    public function del(){
        $map['id']      =I("request.id");
        $map['state']   =3;
        if($this->db->edits($map)){            
            $this->success("删除成功",U("index"));
        }else{
            $this->error("删除失败",U("index"));
        }
    }
}

